package web

import (
	"log/slog"
	"net/http"

	"gitee.com/thinkerwolf/GoStudy/struction"
	"gitee.com/thinkerwolf/GoStudy/util"
)

var googlePlayListPlanUrl = "/api/site/googlePlay/listPlans/v1"
var googlePlayCreateOrderUrl = "/api/bill/googlePlay/order/create/v1"
var googlePlayListOrderUrl = "/api/bill/googlePlay/order/list/v1"

// 获取Google Play套餐列表
func GooglePlayGetPlanList(host string) error {
	req := struction.GooglePlayListPlanReq{Uid: 14000000014, Account: "wukai_reign@163.com", Language: "en", Client: "app", ClientIp: "127.0.0.1"}
	httpReq, err := util.CreateMemberSiteJsonRequest(host+googlePlayListPlanUrl, struction.XTenantAuthorization, "2000008", "5143c53573184294", req)
	if err != nil {
		slog.Error("Create request", "err", err)
		return err
	}
	httpResp, err := http.DefaultClient.Do(httpReq)
	if err != nil {
		slog.Error("Send request", "err", err)
		return err
	}

	defer httpResp.Body.Close()
	util.LogHttpResponse(httpResp)
	return nil
}

// 创建订单
func GooglePlayCreateOrder(host string, req *struction.GooglePlayPayOrderReq) error {
	httpReq, err := util.CreateMemberSiteJsonRequest(host+googlePlayCreateOrderUrl, struction.XTenantAuthorization, "2000008", "5143c53573184294", req)
	if err != nil {
		slog.Error("Create request", "err", err)
		return err
	}
	httpResp, err := http.DefaultClient.Do(httpReq)
	if err != nil {
		slog.Error("Send request", "err", err)
		return err
	}
	defer httpResp.Body.Close()
	util.LogHttpResponse(httpResp)
	return nil
}

func GooglePlayListOrder(host string, req *struction.GooglePlayListOrderReq) error {
	httpReq, err := util.CreateMemberSiteJsonRequest(host+googlePlayListOrderUrl, struction.XTenantAuthorization, "2000008", "5143c53573184294", req)
	if err != nil {
		slog.Error("Create request", "err", err)
		return err
	}
	httpResp, err := http.DefaultClient.Do(httpReq)
	if err != nil {
		slog.Error("Send request", "err", err)
		return err
	}
	defer httpResp.Body.Close()
	util.LogHttpResponse(httpResp)
	return nil
}
